const path = require('path')
const pxtorem = require('postcss-pxtorem')
const postcss = pxtorem({
  rootValue: 11.8,
  unitPrecision: 5,
  propList: ['*'],
  selectorBlackList: [],
  replace: true,
  mediaQuery: false,
  minPixelValue: 0,
  exclude: function (file) {
    const exclude = ['views\\index\\index_A']
    return exclude.find(src => file.indexOf(src) !== -1)
  }
})

function resolve (dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  publicPath: process.env.NODE_ENV === 'production' ? '/pad' : '/',
  devServer: {
    host: '0.0.0.0',
    port: 3000,
    open: true,
    disableHostCheck: true,
    proxy: {
      '/api/*': {
        target: process.env.NODE_ENV !== 'production' ? 'http://192.168.31.126:8005' : 'http://192.168.2.30:9098',
        changeOrigin: true,
        secure: false,
        pathRewrite:{
          '^/api':'/api'
        }
      },
    }
  },

  configureWebpack: config => {
    let _config = {}
    _config.resolve = {
      alias: {
        utils: resolve('src/utils'),
        api: resolve('src/assets/api/index.js')
      }
    }
    if (process.env.NODE_ENV === 'production') {
      _config.plugins = []
    }
    return _config
  },
  css: {
    loaderOptions: {
      postcss: {
        plugins: [postcss],
      }
    }
  },

  outputDir: 'dist',
  assetsDir: 'static',
  runtimeCompiler: false,
  productionSourceMap: false,
  filenameHashing: true,
  integrity: false
}
